package cn.edu.xmu.oomall.wechatpay.mq;

import cn.edu.xmu.oomall.wechatpay.microservice.WeChatPayNotifyService;
import cn.edu.xmu.oomall.wechatpay.model.vo.WeChatPayRefundNotifyRetVo;
import cn.edu.xmu.oomall.wechatpay.util.Constant;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;

import javax.annotation.Resource;
import java.time.LocalDateTime;


@Service
@RocketMQMessageListener(topic = "wechatpayrefund-topic1", consumeMode = ConsumeMode.CONCURRENTLY, consumerGroup = "wechatpayrefund-group1")
public class RefundNotifyService implements RocketMQListener<String> {
    @Resource
    WeChatPayNotifyService weChatPayNotifyService;

    @Override
    public void onMessage(String json) {
        //System.out.println(LocalDateTime.now()+":微信发送退款结果通过回调给支付系统"+json);

        RequestContextHolder.setRequestAttributes(Constant.servletRequestAttributes);
        WeChatPayRefundNotifyRetVo weChatPayRefundNotifyRetVo= JSONObject.parseObject(json,WeChatPayRefundNotifyRetVo.class);

        weChatPayNotifyService.refundNotify(weChatPayRefundNotifyRetVo);
        //System.out.println(LocalDateTime.now()+":微信发送退款结果通过回调给支付系统成功");

    }
}